import Cookies from "js-cookie";
import store from "@/store";
const TokenKey = "Business-Token";

export function getToken() {
  return store.state.auth.token;
}

export function setToken(token) {
  return store.dispatch("auth/setToken", token);
}

export function removeToken() {
  return store.dispatch("auth/setToken", "");
}

// 授权在cookie对token的操作

export function getCookies(cname) {
  const name = cname + "=";
  const ca = document.cookie.split(";");
  for (let i = 0; i < ca.length; i++) {
    const c = ca[i].trim();
    if (c.indexOf(name) === 0) return c.substring(name.length, c.length);
  }
  return "";
}

export function setCookies(cname, val, expires) {
  document.cookie = `${cname}=${val};expires=${expires}`;
}

export function removeCookies(cname) {
  document.cookie = `${cname}=;expires=Thu, 01 Jan 1970 00:00:00 UTC;`;
}
